using System;
using System.Collections;
using System.Collections.Generic;
using System.Drawing;
using System.Globalization;
using PickGold.Charting;
using PickGold.Charting.Utilities;

namespace PickGold.Charting.ChartTypes
{
	internal class ErrorBarChart : IChartType, IDisposable
	{
		protected Axis hAxis;
		protected Axis vAxis;

		public void AddSmartLabelMarkerPositions(CommonElements common, ChartArea area, Series series, ArrayList list)
		{
		}

		internal static void CalculateErrorAmount(Series errorBarSeries)
		{
			if ((string.Compare(errorBarSeries.ChartTypeName, "ErrorBar", StringComparison.OrdinalIgnoreCase) == 0) && (errorBarSeries.IsCustomPropertySet("ErrorBarType") || errorBarSeries.IsCustomPropertySet("ErrorBarSeries")))
			{
				double naN = double.NaN;
				ErrorBarType standardError = ErrorBarType.StandardError;
				if (errorBarSeries.IsCustomPropertySet("ErrorBarType"))
				{
					string s = errorBarSeries["ErrorBarType"];
					if (s.StartsWith("FixedValue", StringComparison.OrdinalIgnoreCase))
					{
						standardError = ErrorBarType.FixedValue;
					}
					else if (s.StartsWith("Percentage", StringComparison.OrdinalIgnoreCase))
					{
						standardError = ErrorBarType.Percentage;
					}
					else if (s.StartsWith("StandardDeviation", StringComparison.OrdinalIgnoreCase))
					{
						standardError = ErrorBarType.StandardDeviation;
					}
					else if (s.StartsWith("StandardError", StringComparison.OrdinalIgnoreCase))
					{
						standardError = ErrorBarType.StandardError;
					}
					else
					{
						if (!s.StartsWith("None", StringComparison.OrdinalIgnoreCase))
						{
							throw new InvalidOperationException(SR.ExceptionErrorBarTypeInvalid(errorBarSeries["ErrorBarType"]));
						}
						return;
					}
					s = s.Substring(standardError.ToString().Length);
					if (s.Length > 0)
					{
						if (!s.StartsWith("(", StringComparison.Ordinal) || !s.EndsWith(")", StringComparison.Ordinal))
						{
							throw new InvalidOperationException(SR.ExceptionErrorBarTypeFormatInvalid(errorBarSeries["ErrorBarType"]));
						}
						s = s.Substring(1, s.Length - 2);
						if ((s.Length > 0) && !double.TryParse(s, NumberStyles.Any, CultureInfo.InvariantCulture, out naN))
						{
							throw new InvalidOperationException(SR.ExceptionErrorBarTypeFormatInvalid(errorBarSeries["ErrorBarType"]));
						}
					}
				}
				int count = errorBarSeries.Points.Count;
				int num3 = 0;
				foreach (DataPoint point in errorBarSeries.Points)
				{
					if (point.IsEmpty)
					{
						num3++;
					}
				}
				count -= num3;
				double num4 = 0.0;
				switch (standardError)
				{
					case ErrorBarType.FixedValue:
						if (double.IsNaN(naN))
						{
							throw new InvalidOperationException(SR.ExceptionErrorBarParameterUndefined);
						}
						num4 = naN;
						break;

					case ErrorBarType.Percentage:
						if (double.IsNaN(naN))
						{
							naN = 10.0;
						}
						break;

					case ErrorBarType.StandardDeviation:
						if (double.IsNaN(naN))
						{
							naN = 1.0;
						}
						if (count > 1)
						{
							double num5 = 0.0;
							foreach (DataPoint point2 in errorBarSeries.Points)
							{
								num5 += point2.YValues[0];
							}
							num5 /= (double)count;
							num4 = 0.0;
							foreach (DataPoint point3 in errorBarSeries.Points)
							{
								if (!point3.IsEmpty)
								{
									num4 += Math.Pow(point3.YValues[0] - num5, 2.0);
								}
							}
							num4 = naN * Math.Sqrt(num4 / ((double)(count - 1)));
						}
						else
						{
							num4 = 0.0;
						}
						break;

					case ErrorBarType.StandardError:
						if (double.IsNaN(naN))
						{
							naN = 1.0;
						}
						if (count > 1)
						{
							num4 = 0.0;
							foreach (DataPoint point4 in errorBarSeries.Points)
							{
								if (!point4.IsEmpty)
								{
									num4 += Math.Pow(point4.YValues[0], 2.0);
								}
							}
							num4 = (naN * Math.Sqrt(num4 / ((double)(count * (count - 1))))) / 2.0;
						}
						else
						{
							num4 = 0.0;
						}
						break;
				}
				foreach (DataPoint point5 in errorBarSeries.Points)
				{
					if (standardError == ErrorBarType.Percentage)
					{
						point5.YValues[1] = point5.YValues[0] - ((point5.YValues[0] * naN) / 100.0);
						point5.YValues[2] = point5.YValues[0] + ((point5.YValues[0] * naN) / 100.0);
					}
					else
					{
						point5.YValues[1] = point5.YValues[0] - num4;
						point5.YValues[2] = point5.YValues[0] + num4;
					}
				}
			}
		}

		public void Dispose()
		{
			this.Dispose(true);
			GC.SuppressFinalize(this);
		}

		protected virtual void Dispose(bool disposing)
		{
		}

		protected virtual void DrawErrorBarMarks(ChartGraphics graph, ErrorBarStyle barStyle, ChartArea area, Series ser, DataPoint point, float xPosition, float width)
		{
			double logValue = 0.0;
			string markerStyle = string.Empty;
			if ((barStyle == ErrorBarStyle.Both) || (barStyle == ErrorBarStyle.LowerError))
			{
				logValue = this.vAxis.GetLogValue(point.YValues[1]);
				markerStyle = "LINE";
				if (point.MarkerStyle != MarkerStyle.None)
				{
					markerStyle = point.MarkerStyle.ToString();
				}
				this.DrawErrorBarSingleMarker(graph, area, point, markerStyle, xPosition, (float)logValue, 0f, width, false);
			}
			if ((barStyle == ErrorBarStyle.Both) || (barStyle == ErrorBarStyle.UpperError))
			{
				logValue = this.vAxis.GetLogValue(point.YValues[2]);
				markerStyle = "LINE";
				if (point.MarkerStyle != MarkerStyle.None)
				{
					markerStyle = point.MarkerStyle.ToString();
				}
				this.DrawErrorBarSingleMarker(graph, area, point, markerStyle, xPosition, (float)logValue, 0f, width, false);
			}
			if (point.IsCustomPropertySet("ErrorBarCenterMarkerStyle") || point.series.IsCustomPropertySet("ErrorBarCenterMarkerStyle"))
			{
				logValue = this.vAxis.GetLogValue(point.YValues[0]);
				markerStyle = point.series["ErrorBarCenterMarkerStyle"];
				if (point.IsCustomPropertySet("ErrorBarCenterMarkerStyle"))
				{
					markerStyle = point["ErrorBarCenterMarkerStyle"];
				}
				markerStyle = markerStyle.ToUpper(CultureInfo.InvariantCulture);
				this.DrawErrorBarSingleMarker(graph, area, point, markerStyle, xPosition, (float)logValue, 0f, width, false);
			}
		}

		protected virtual void DrawErrorBarMarks3D(ChartGraphics graph, ErrorBarStyle barStyle, ChartArea area, Series ser, DataPoint point, float xPosition, float width, float zPosition, float depth)
		{
			float yPosition = 0f;
			string markerStyle = string.Empty;
			if ((barStyle == ErrorBarStyle.Both) || (barStyle == ErrorBarStyle.LowerError))
			{
				yPosition = (float)this.vAxis.GetLogValue(point.YValues[1]);
				markerStyle = "LINE";
				if (point.MarkerStyle != MarkerStyle.None)
				{
					markerStyle = point.MarkerStyle.ToString();
				}
				this.DrawErrorBarSingleMarker(graph, area, point, markerStyle, xPosition, yPosition, zPosition + (depth / 2f), width, true);
			}
			if ((barStyle == ErrorBarStyle.Both) || (barStyle == ErrorBarStyle.UpperError))
			{
				yPosition = (float)this.vAxis.GetLogValue(point.YValues[2]);
				markerStyle = "LINE";
				if (point.MarkerStyle != MarkerStyle.None)
				{
					markerStyle = point.MarkerStyle.ToString();
				}
				this.DrawErrorBarSingleMarker(graph, area, point, markerStyle, xPosition, yPosition, zPosition + (depth / 2f), width, true);
			}
			if (point.IsCustomPropertySet("ErrorBarCenterMarkerStyle") || point.series.IsCustomPropertySet("ErrorBarCenterMarkerStyle"))
			{
				yPosition = (float)this.vAxis.GetLogValue(point.YValues[0]);
				markerStyle = point.series["ErrorBarCenterMarkerStyle"];
				if (point.IsCustomPropertySet("ErrorBarCenterMarkerStyle"))
				{
					markerStyle = point["ErrorBarCenterMarkerStyle"];
				}
				markerStyle = markerStyle.ToUpper(CultureInfo.InvariantCulture);
				this.DrawErrorBarSingleMarker(graph, area, point, markerStyle, xPosition, yPosition, zPosition + (depth / 2f), width, true);
			}
		}

		private void DrawErrorBarSingleMarker(ChartGraphics graph, ChartArea area, DataPoint point, string markerStyle, float xPosition, float yPosition, float zPosition, float width, bool draw3D)
		{
			markerStyle = markerStyle.ToUpper(CultureInfo.InvariantCulture);
			if (((markerStyle.Length > 0) && (string.Compare(markerStyle, "None", StringComparison.OrdinalIgnoreCase) != 0)) && ((yPosition <= this.vAxis.ViewMaximum) && (yPosition >= this.vAxis.ViewMinimum)))
			{
				yPosition = (float)this.vAxis.GetLinearPosition((double)yPosition);
				if (draw3D)
				{
					Point3D[] points = new Point3D[] { new Point3D(xPosition, yPosition, zPosition) };
					area.matrix3D.TransformPoints(points);
					xPosition = points[0].X;
					yPosition = points[0].Y;
				}
				if (string.Compare(markerStyle, "Line", StringComparison.OrdinalIgnoreCase) == 0)
				{
					graph.DrawLineRel(point.Color, point.BorderWidth, point.BorderDashStyle, new PointF(xPosition - (width / 2f), yPosition), new PointF(xPosition + (width / 2f), yPosition), (point.series != null) ? point.series.ShadowColor : Color.Empty, (point.series != null) ? point.series.ShadowOffset : 0);
				}
				else
				{
					MarkerStyle style = (MarkerStyle)Enum.Parse(typeof(MarkerStyle), markerStyle, true);
					SizeF ef = this.GetMarkerSize(graph, area.Common, area, point, point.MarkerSize, point.MarkerImage);
					Color markerColor = (point.MarkerColor == Color.Empty) ? point.Color : point.MarkerColor;
					graph.DrawMarkerRel(new PointF(xPosition, yPosition), style, point.MarkerSize, markerColor, point.MarkerBorderColor, point.MarkerBorderWidth, point.MarkerImage, point.MarkerImageTransparentColor, (point.series != null) ? point.series.ShadowOffset : 0, (point.series != null) ? point.series.ShadowColor : Color.Empty, new RectangleF(xPosition, yPosition, ef.Width, ef.Height));
				}
			}
		}

		protected virtual void DrawLabel(CommonElements common, ChartArea area, ChartGraphics graph, Series ser, DataPoint point, PointF position, int pointIndex)
		{
			if ((ser.IsValueShownAsLabel || point.IsValueShownAsLabel) || (point.Label.Length > 0))
			{
				using (StringFormat format = new StringFormat())
				{
					string str;
					format.Alignment = StringAlignment.Near;
					format.LineAlignment = StringAlignment.Center;
					if (point.LabelAngle == 0)
					{
						format.Alignment = StringAlignment.Center;
						format.LineAlignment = StringAlignment.Far;
					}
					if (point.Label.Length == 0)
					{
						str = ValueConverter.FormatValue(ser.Chart, point, point.Tag, point.YValues[0], point.LabelFormat, ser.YValueType, ChartElementType.DataPoint);
					}
					else
					{
						str = point.ReplaceKeywords(point.Label);
					}
					SizeF markerSize = new SizeF(0f, 0f);
					if (point.MarkerStyle != MarkerStyle.None)
					{
						markerSize = graph.GetRelativeSize(new SizeF((float)point.MarkerSize, (float)point.MarkerSize));
						position.Y -= markerSize.Height / 2f;
					}
					int labelAngle = point.LabelAngle;
					if (str.Trim().Length != 0)
					{
						SizeF empty = SizeF.Empty;
						if (ser.SmartLabelStyle.Enabled)
						{
							empty = graph.GetRelativeSize(graph.MeasureString(str, point.Font, new SizeF(1000f, 1000f), StringFormat.GenericTypographic));
							position = area.smartLabels.AdjustSmartLabelPosition(common, graph, area, ser.SmartLabelStyle, position, empty, format, position, markerSize, LabelAlignmentStyles.Top);
							labelAngle = 0;
						}
						if (!position.IsEmpty)
						{
							if (empty.IsEmpty)
							{
								empty = graph.GetRelativeSize(graph.MeasureString(str, point.Font, new SizeF(1000f, 1000f), StringFormat.GenericTypographic));
							}
							RectangleF backPosition = RectangleF.Empty;
							SizeF size = new SizeF(empty.Width, empty.Height);
							size.Height += empty.Height / 8f;
							size.Width += size.Width / ((float)str.Length);
							backPosition = PointChart.GetLabelPosition(graph, position, size, format, true);
							using (Brush brush = new SolidBrush(point.LabelForeColor))
							{
								graph.DrawPointLabelStringRel(common, str, point.Font, brush, position, format, labelAngle, backPosition, point.LabelBackColor, point.LabelBorderColor, point.LabelBorderWidth, point.LabelBorderDashStyle, ser, point, pointIndex - 1);
							}
						}
					}
				}
			}
		}

		internal static void GetDataFromLinkedSeries(Series errorBarSeries)
		{
			if (((string.Compare(errorBarSeries.ChartTypeName, "ErrorBar", StringComparison.OrdinalIgnoreCase) == 0) && (errorBarSeries.Chart != null)) && errorBarSeries.IsCustomPropertySet("ErrorBarSeries"))
			{
				string name = errorBarSeries["ErrorBarSeries"];
				string valueName = "Y";
				int index = name.IndexOf(":", StringComparison.Ordinal);
				if (index >= 0)
				{
					valueName = name.Substring(index + 1);
					name = name.Substring(0, index);
				}
				Chart chart = errorBarSeries.Chart;
				if (chart != null)
				{
					if (chart.Series.IndexOf(name) == -1)
					{
						throw new InvalidOperationException(SR.ExceptionDataSeriesNameNotFound(name));
					}
					Series series = chart.Series[name];
					errorBarSeries.XAxisType = series.XAxisType;
					errorBarSeries.YAxisType = series.YAxisType;
					errorBarSeries.Points.Clear();
					foreach (DataPoint point in series.Points)
					{
						errorBarSeries.Points.AddXY(point.XValue, point.GetValueByName(valueName));
					}
				}
			}
		}

		public virtual Image GetImage(ChartTypeRegistry registry)
		{
			return (Image)registry.ResourceManager.GetObject(this.Name + "ChartType");
		}

		public virtual LegendImageStyle GetLegendImageStyle(Series series)
		{
			return LegendImageStyle.Line;
		}

		protected virtual SizeF GetMarkerSize(ChartGraphics graph, CommonElements common, ChartArea area, DataPoint point, int markerSize, string markerImage)
		{
			SizeF size = new SizeF((float)markerSize, (float)markerSize);
			if ((graph != null) && (graph.Graphics != null))
			{
				size.Width = (markerSize * graph.Graphics.DpiX) / 96f;
				size.Height = (markerSize * graph.Graphics.DpiY) / 96f;
			}
			if (markerImage.Length > 0)
			{
				common.ImageLoader.GetAdjustedImageSize(markerImage, graph.Graphics, ref size);
			}
			return size;
		}

		public virtual double GetYValue(CommonElements common, ChartArea area, Series series, DataPoint point, int pointIndex, int yValueIndex)
		{
			return point.YValues[yValueIndex];
		}

		public virtual void Paint(ChartGraphics graph, CommonElements common, ChartArea area, Series seriesToDraw)
		{
			this.ProcessChartType(false, graph, common, area, seriesToDraw);
		}

		protected virtual void ProcessChartType(bool selection, ChartGraphics graph, CommonElements common, ChartArea area, Series seriesToDraw)
		{
			if (area.Area3DStyle.Enable3D)
			{
				this.ProcessChartType3D(selection, graph, common, area, seriesToDraw);
			}
			else
			{
				List<string> seriesFromChartType = area.GetSeriesFromChartType(this.Name);
				bool flag = ChartHelper.IndexedSeries(common, seriesFromChartType.ToArray());
				int num = 0;
				foreach (Series series in common.DataManager.Series)
				{
					if (((string.Compare(series.ChartTypeName, this.Name, StringComparison.OrdinalIgnoreCase) != 0) || (series.ChartArea != area.Name)) || !series.IsVisible())
					{
						continue;
					}
					this.hAxis = area.GetAxis(AxisName.X, series.XAxisType, series.XSubAxisName);
					this.vAxis = area.GetAxis(AxisName.Y, series.YAxisType, series.YSubAxisName);
					double interval = flag ? 1.0 : area.GetPointsInterval(this.hAxis.IsLogarithmic, this.hAxis.logarithmBase);
					float width = (float)series.GetPointWidth(graph, this.hAxis, interval, 0.4);
					float num4 = width;
					int count = 1;
					int num6 = 0;
					bool sameInterval = false;
					string str = string.Empty;
					bool flag3 = false;
					if (series.IsCustomPropertySet("ErrorBarSeries"))
					{
						str = series["ErrorBarSeries"];
						int index = str.IndexOf(":", StringComparison.Ordinal);
						if (index >= 0)
						{
							str = str.Substring(0, index);
						}
						string chartTypeName = common.DataManager.Series[str].ChartTypeName;
						List<string> seriesList = common.ChartPicture.ChartAreas[common.DataManager.Series[str].ChartArea].GetSeriesFromChartType(chartTypeName);
						foreach (string str3 in seriesList)
						{
							if (str3 == str)
							{
								break;
							}
							num6++;
						}
						flag3 = false;
						if ((string.Compare(chartTypeName, "Column", StringComparison.OrdinalIgnoreCase) == 0) || (string.Compare(chartTypeName, "RangeColumn", StringComparison.OrdinalIgnoreCase) == 0))
						{
							flag3 = true;
						}
						foreach (string str4 in seriesList)
						{
							if (common.DataManager.Series[str4].IsCustomPropertySet("DrawSideBySide"))
							{
								string strA = common.DataManager.Series[str4]["DrawSideBySide"];
								if (string.Compare(strA, "False", StringComparison.OrdinalIgnoreCase) == 0)
								{
									flag3 = false;
								}
								else
								{
									if (string.Compare(strA, "True", StringComparison.OrdinalIgnoreCase) == 0)
									{
										flag3 = true;
										continue;
									}
									if (string.Compare(strA, "Auto", StringComparison.OrdinalIgnoreCase) != 0)
									{
										throw new InvalidOperationException(SR.ExceptionAttributeDrawSideBySideInvalid);
									}
								}
							}
						}
						if (flag3)
						{
							count = seriesList.Count;
							width /= (float)count;
							sameInterval = true;
							if (!flag)
							{
								area.GetPointsInterval(seriesList, this.hAxis.IsLogarithmic, this.hAxis.logarithmBase, true, out sameInterval);
							}
							num4 = ((float)common.DataManager.Series[str].GetPointWidth(graph, this.hAxis, interval, 0.8)) / ((float)count);
						}
					}
					if (!flag3 && series.IsCustomPropertySet("DrawSideBySide"))
					{
						string str6 = series["DrawSideBySide"];
						if (string.Compare(str6, "False", StringComparison.OrdinalIgnoreCase) == 0)
						{
							sameInterval = false;
						}
						else if (string.Compare(str6, "True", StringComparison.OrdinalIgnoreCase) == 0)
						{
							sameInterval = true;
							count = seriesFromChartType.Count;
							num6 = num;
							width /= (float)count;
							num4 = ((float)series.GetPointWidth(graph, this.hAxis, interval, 0.8)) / ((float)count);
						}
						else if (string.Compare(str6, "Auto", StringComparison.OrdinalIgnoreCase) != 0)
						{
							throw new InvalidOperationException(SR.ExceptionAttributeDrawSideBySideInvalid);
						}
					}
					if (!selection)
					{
						common.Chart.CallOnPrePaint(new ChartPaintEventArgs(series, graph, common, area.PlotAreaPosition));
					}
					int pointIndex = 1;
					foreach (DataPoint point in series.Points)
					{
						if (point.YValues.Length < this.YValuesPerPoint)
						{
							throw new InvalidOperationException(SR.ExceptionChartTypeRequiresYValues(this.Name, this.YValuesPerPoint.ToString(CultureInfo.InvariantCulture)));
						}
						point.positionRel = new PointF(float.NaN, float.NaN);
						float x = 0f;
						double xValue = point.XValue;
						if (flag)
						{
							xValue = pointIndex;
						}
						if (sameInterval)
						{
							x = (((float)(this.hAxis.GetPosition(xValue) - ((num4 * count) / 2.0))) + (num4 / 2f)) + (num6 * num4);
						}
						else
						{
							x = (float)this.hAxis.GetPosition(xValue);
						}
						double logValue = this.vAxis.GetLogValue(point.YValues[1]);
						double num12 = this.vAxis.GetLogValue(point.YValues[2]);
						xValue = this.hAxis.GetLogValue(xValue);
						if ((((xValue < this.hAxis.ViewMinimum) || (xValue > this.hAxis.ViewMaximum)) || ((logValue < this.vAxis.ViewMinimum) && (num12 < this.vAxis.ViewMinimum))) || ((logValue > this.vAxis.ViewMaximum) && (num12 > this.vAxis.ViewMaximum)))
						{
							pointIndex++;
							continue;
						}
						double axisValue = this.vAxis.GetLogValue(point.YValues[1]);
						double linearPosition = this.vAxis.GetLogValue(point.YValues[2]);
						ErrorBarStyle both = ErrorBarStyle.Both;
						if (point.IsCustomPropertySet("ErrorBarStyle") || series.IsCustomPropertySet("ErrorBarStyle"))
						{
							string str7 = series["ErrorBarStyle"];
							if (point.IsCustomPropertySet("ErrorBarStyle"))
							{
								str7 = point["ErrorBarStyle"];
							}
							if (string.Compare(str7, "Both", StringComparison.OrdinalIgnoreCase) != 0)
							{
								if (string.Compare(str7, "UpperError", StringComparison.OrdinalIgnoreCase) != 0)
								{
									if (string.Compare(str7, "LowerError", StringComparison.OrdinalIgnoreCase) != 0)
									{
										throw new InvalidOperationException(SR.ExceptionCustomAttributeValueInvalid(point["ErrorBarStyle"], "ErrorBarStyle"));
									}
									both = ErrorBarStyle.LowerError;
									axisValue = this.vAxis.GetLogValue(point.YValues[1]);
									linearPosition = this.vAxis.GetLogValue(point.YValues[0]);
								}
								else
								{
									both = ErrorBarStyle.UpperError;
									axisValue = this.vAxis.GetLogValue(point.YValues[0]);
									linearPosition = this.vAxis.GetLogValue(point.YValues[2]);
								}
							}
						}
						if (linearPosition > this.vAxis.ViewMaximum)
						{
							linearPosition = this.vAxis.ViewMaximum;
						}
						if (linearPosition < this.vAxis.ViewMinimum)
						{
							linearPosition = this.vAxis.ViewMinimum;
						}
						linearPosition = (float)this.vAxis.GetLinearPosition(linearPosition);
						if (axisValue > this.vAxis.ViewMaximum)
						{
							axisValue = this.vAxis.ViewMaximum;
						}
						if (axisValue < this.vAxis.ViewMinimum)
						{
							axisValue = this.vAxis.ViewMinimum;
						}
						axisValue = this.vAxis.GetLinearPosition(axisValue);
						point.positionRel = new PointF(x, (float)Math.Min(linearPosition, axisValue));
						if (common.ProcessModePaint)
						{
							bool flag4 = false;
							if ((xValue == this.hAxis.ViewMinimum) || (xValue == this.hAxis.ViewMaximum))
							{
								graph.SetClip(area.PlotAreaPosition.ToRectangleF());
								flag4 = true;
							}
							graph.StartHotRegion(point);
							graph.DrawLineRel(point.Color, point.BorderWidth, point.BorderDashStyle, new PointF(x, (float)linearPosition), new PointF(x, (float)axisValue), series.ShadowColor, series.ShadowOffset);
							this.DrawErrorBarMarks(graph, both, area, series, point, x, width);
							graph.EndHotRegion();
							if (flag4)
							{
								graph.ResetClip();
							}
						}
						if (common.ProcessModeRegions)
						{
							RectangleF empty = RectangleF.Empty;
							empty.X = x - (width / 2f);
							empty.Y = (float)Math.Min(linearPosition, axisValue);
							empty.Width = width;
							empty.Height = ((float)Math.Max(linearPosition, axisValue)) - empty.Y;
							common.HotRegionsList.AddHotRegion(empty, point, series.Name, pointIndex - 1);
						}
						pointIndex++;
					}
					if (!selection)
					{
						pointIndex = 1;
						foreach (DataPoint point2 in series.Points)
						{
							float position = 0f;
							double num16 = point2.XValue;
							if (flag)
							{
								num16 = pointIndex;
								position = (((float)(this.hAxis.GetPosition((double)pointIndex) - ((num4 * count) / 2.0))) + (num4 / 2f)) + (num6 * num4);
							}
							else if (sameInterval)
							{
								position = (((float)(this.hAxis.GetPosition(num16) - ((num4 * count) / 2.0))) + (num4 / 2f)) + (num6 * num4);
							}
							else
							{
								position = (float)this.hAxis.GetPosition(num16);
							}
							double num17 = this.vAxis.GetLogValue(point2.YValues[1]);
							double num18 = this.vAxis.GetLogValue(point2.YValues[2]);
							num16 = this.hAxis.GetLogValue(num16);
							if ((((num16 < this.hAxis.ViewMinimum) || (num16 > this.hAxis.ViewMaximum)) || ((num17 < this.vAxis.ViewMinimum) && (num18 < this.vAxis.ViewMinimum))) || ((num17 > this.vAxis.ViewMaximum) && (num18 > this.vAxis.ViewMaximum)))
							{
								pointIndex++;
								continue;
							}
							double viewMaximum = this.vAxis.GetLogValue(point2.YValues[1]);
							double viewMinimum = this.vAxis.GetLogValue(point2.YValues[2]);
							if (point2.IsCustomPropertySet("ErrorBarStyle") || series.IsCustomPropertySet("ErrorBarStyle"))
							{
								string str8 = series["ErrorBarStyle"];
								if (point2.IsCustomPropertySet("ErrorBarStyle"))
								{
									str8 = point2["ErrorBarStyle"];
								}
								if (string.Compare(str8, "Both", StringComparison.OrdinalIgnoreCase) != 0)
								{
									if (string.Compare(str8, "UpperError", StringComparison.OrdinalIgnoreCase) != 0)
									{
										if (string.Compare(str8, "LowerError", StringComparison.OrdinalIgnoreCase) != 0)
										{
											throw new InvalidOperationException(SR.ExceptionCustomAttributeValueInvalid(point2["ErrorBarStyle"], "ErrorBarStyle"));
										}
										viewMinimum = this.vAxis.GetLogValue(point2.YValues[1]);
										viewMaximum = this.vAxis.GetLogValue(point2.YValues[0]);
									}
									else
									{
										viewMinimum = this.vAxis.GetLogValue(point2.YValues[0]);
										viewMaximum = this.vAxis.GetLogValue(point2.YValues[2]);
									}
								}
							}
							if (viewMaximum > this.vAxis.ViewMaximum)
							{
								viewMaximum = this.vAxis.ViewMaximum;
							}
							if (viewMaximum < this.vAxis.ViewMinimum)
							{
								viewMaximum = this.vAxis.ViewMinimum;
							}
							viewMaximum = (float)this.vAxis.GetLinearPosition(viewMaximum);
							if (viewMinimum > this.vAxis.ViewMaximum)
							{
								viewMinimum = this.vAxis.ViewMaximum;
							}
							if (viewMinimum < this.vAxis.ViewMinimum)
							{
								viewMinimum = this.vAxis.ViewMinimum;
							}
							viewMinimum = this.vAxis.GetLinearPosition(viewMinimum);
							graph.StartHotRegion(point2, true);
							this.DrawLabel(common, area, graph, series, point2, new PointF(position, (float)Math.Min(viewMaximum, viewMinimum)), pointIndex);
							graph.EndHotRegion();
							pointIndex++;
						}
					}
					if (!selection)
					{
						common.Chart.CallOnPostPaint(new ChartPaintEventArgs(series, graph, common, area.PlotAreaPosition));
					}
					num++;
				}
			}
		}

		protected virtual void ProcessChartType3D(bool selection, ChartGraphics graph, CommonElements common, ChartArea area, Series seriesToDraw)
		{
			bool flag = ChartHelper.IndexedSeries(common, area.GetSeriesFromChartType(this.Name).ToArray());
			foreach (Series series in common.DataManager.Series)
			{
				float num7;
				float num8;
				if (((string.Compare(series.ChartTypeName, this.Name, StringComparison.OrdinalIgnoreCase) != 0) || (series.ChartArea != area.Name)) || !series.IsVisible())
				{
					continue;
				}
				if (series.YValuesPerPoint < 3)
				{
					int num22 = 3;
					throw new ArgumentException(SR.ExceptionChartTypeRequiresYValues("ErrorBar", num22.ToString(CultureInfo.CurrentCulture)));
				}
				this.hAxis = area.GetAxis(AxisName.X, series.XAxisType, series.XSubAxisName);
				this.vAxis = area.GetAxis(AxisName.Y, series.YAxisType, series.YSubAxisName);
				double interval = flag ? 1.0 : area.GetPointsInterval(this.hAxis.IsLogarithmic, this.hAxis.logarithmBase);
				float width = (float)series.GetPointWidth(graph, this.hAxis, interval, 0.4);
				float num3 = width;
				int count = 1;
				int num5 = 0;
				bool sameInterval = false;
				if (series.IsCustomPropertySet("ErrorBarSeries"))
				{
					string strA = series["ErrorBarSeries"];
					int index = strA.IndexOf(":", StringComparison.Ordinal);
					if (index >= 0)
					{
						strA = strA.Substring(0, index);
					}
					string chartTypeName = common.DataManager.Series[strA].ChartTypeName;
					List<string> seriesFromChartType = area.GetSeriesFromChartType(chartTypeName);
					foreach (string str3 in seriesFromChartType)
					{
						if (str3 == strA)
						{
							break;
						}
						num5++;
					}
					bool flag3 = false;
					if ((string.Compare(chartTypeName, "Column", StringComparison.OrdinalIgnoreCase) == 0) || (string.Compare(chartTypeName, "RangeColumn", StringComparison.OrdinalIgnoreCase) == 0))
					{
						flag3 = true;
					}
					foreach (string str4 in seriesFromChartType)
					{
						if (common.DataManager.Series[str4].IsCustomPropertySet("DrawSideBySide"))
						{
							strA = common.DataManager.Series[str4]["DrawSideBySide"];
							if (string.Compare(strA, "False", StringComparison.OrdinalIgnoreCase) == 0)
							{
								flag3 = false;
							}
							else
							{
								if (string.Compare(strA, "True", StringComparison.OrdinalIgnoreCase) == 0)
								{
									flag3 = true;
									continue;
								}
								if (string.Compare(strA, "Auto", StringComparison.OrdinalIgnoreCase) != 0)
								{
									throw new InvalidOperationException(SR.ExceptionAttributeDrawSideBySideInvalid);
								}
							}
						}
					}
					if (flag3)
					{
						count = seriesFromChartType.Count;
						width /= (float)count;
						if (!flag)
						{
							area.GetPointsInterval(seriesFromChartType, this.hAxis.IsLogarithmic, this.hAxis.logarithmBase, true, out sameInterval);
						}
					}
				}
				if (!selection)
				{
					common.Chart.CallOnPrePaint(new ChartPaintEventArgs(series, graph, common, area.PlotAreaPosition));
				}
				area.GetSeriesZPositionAndDepth(series, out num7, out num8);
				int pointIndex = 1;
				foreach (DataPoint point in series.Points)
				{
					if (point.YValues.Length < this.YValuesPerPoint)
					{
						throw new InvalidOperationException(SR.ExceptionChartTypeRequiresYValues(this.Name, this.YValuesPerPoint.ToString(CultureInfo.InvariantCulture)));
					}
					point.positionRel = new PointF(float.NaN, float.NaN);
					float x = 0f;
					double xValue = point.XValue;
					if (flag)
					{
						xValue = pointIndex;
						x = (((float)(this.hAxis.GetPosition((double)pointIndex) - ((num3 * count) / 2.0))) + (num3 / 2f)) + (num5 * num3);
					}
					else if (sameInterval)
					{
						x = (((float)(this.hAxis.GetPosition(xValue) - ((num3 * count) / 2.0))) + (num3 / 2f)) + (num5 * num3);
					}
					else
					{
						x = (float)this.hAxis.GetPosition(xValue);
					}
					double logValue = this.vAxis.GetLogValue(point.YValues[1]);
					double num13 = this.vAxis.GetLogValue(point.YValues[2]);
					xValue = this.hAxis.GetLogValue(xValue);
					if ((((xValue < this.hAxis.ViewMinimum) || (xValue > this.hAxis.ViewMaximum)) || ((logValue < this.vAxis.ViewMinimum) && (num13 < this.vAxis.ViewMinimum))) || ((logValue > this.vAxis.ViewMaximum) && (num13 > this.vAxis.ViewMaximum)))
					{
						pointIndex++;
						continue;
					}
					double axisValue = this.vAxis.GetLogValue(point.YValues[2]);
					double linearPosition = this.vAxis.GetLogValue(point.YValues[1]);
					ErrorBarStyle both = ErrorBarStyle.Both;
					if (point.IsCustomPropertySet("ErrorBarStyle") || series.IsCustomPropertySet("ErrorBarStyle"))
					{
						string str5 = series["ErrorBarStyle"];
						if (point.IsCustomPropertySet("ErrorBarStyle"))
						{
							str5 = point["ErrorBarStyle"];
						}
						if (string.Compare(str5, "Both", StringComparison.OrdinalIgnoreCase) != 0)
						{
							if (string.Compare(str5, "UpperError", StringComparison.OrdinalIgnoreCase) != 0)
							{
								if (string.Compare(str5, "LowerError", StringComparison.OrdinalIgnoreCase) != 0)
								{
									throw new InvalidOperationException(SR.ExceptionCustomAttributeValueInvalid(point["ErrorBarStyle"], "ErrorBarStyle"));
								}
								both = ErrorBarStyle.LowerError;
								linearPosition = this.vAxis.GetLogValue(point.YValues[1]);
								axisValue = this.vAxis.GetLogValue(point.YValues[0]);
							}
							else
							{
								both = ErrorBarStyle.UpperError;
								linearPosition = this.vAxis.GetLogValue(point.YValues[0]);
								axisValue = this.vAxis.GetLogValue(point.YValues[2]);
							}
						}
					}
					if (axisValue > this.vAxis.ViewMaximum)
					{
						axisValue = this.vAxis.ViewMaximum;
					}
					if (axisValue < this.vAxis.ViewMinimum)
					{
						axisValue = this.vAxis.ViewMinimum;
					}
					axisValue = (float)this.vAxis.GetLinearPosition(axisValue);
					if (linearPosition > this.vAxis.ViewMaximum)
					{
						linearPosition = this.vAxis.ViewMaximum;
					}
					if (linearPosition < this.vAxis.ViewMinimum)
					{
						linearPosition = this.vAxis.ViewMinimum;
					}
					linearPosition = this.vAxis.GetLinearPosition(linearPosition);
					point.positionRel = new PointF(x, (float)Math.Min(axisValue, linearPosition));
					Point3D[] points = new Point3D[] { new Point3D(x, (float)axisValue, num8 + (num7 / 2f)), new Point3D(x, (float)linearPosition, num8 + (num7 / 2f)) };
					area.matrix3D.TransformPoints(points);
					if (common.ProcessModePaint)
					{
						bool flag4 = false;
						if ((xValue == this.hAxis.ViewMinimum) || (xValue == this.hAxis.ViewMaximum))
						{
							graph.SetClip(area.PlotAreaPosition.ToRectangleF());
							flag4 = true;
						}
						graph.StartHotRegion(point);
						graph.DrawLineRel(point.Color, point.BorderWidth, point.BorderDashStyle, points[0].PointF, points[1].PointF, series.ShadowColor, series.ShadowOffset);
						this.DrawErrorBarMarks3D(graph, both, area, series, point, x, width, num8, num7);
						x = points[0].X;
						axisValue = points[0].Y;
						linearPosition = points[1].Y;
						graph.EndHotRegion();
						if (flag4)
						{
							graph.ResetClip();
						}
					}
					if (common.ProcessModeRegions)
					{
						x = points[0].X;
						axisValue = points[0].Y;
						linearPosition = points[1].Y;
						RectangleF empty = RectangleF.Empty;
						empty.X = x - (width / 2f);
						empty.Y = (float)Math.Min(axisValue, linearPosition);
						empty.Width = width;
						empty.Height = ((float)Math.Max(axisValue, linearPosition)) - empty.Y;
						common.HotRegionsList.AddHotRegion(empty, point, series.Name, pointIndex - 1);
					}
					pointIndex++;
				}
				if (!selection)
				{
					pointIndex = 1;
					foreach (DataPoint point2 in series.Points)
					{
						float position = 0f;
						double num17 = point2.XValue;
						if (flag)
						{
							num17 = pointIndex;
							position = (((float)(this.hAxis.GetPosition((double)pointIndex) - ((num3 * count) / 2.0))) + (num3 / 2f)) + (num5 * num3);
						}
						else if (sameInterval)
						{
							position = (((float)(this.hAxis.GetPosition(num17) - ((num3 * count) / 2.0))) + (num3 / 2f)) + (num5 * num3);
						}
						else
						{
							position = (float)this.hAxis.GetPosition(num17);
						}
						double num18 = this.vAxis.GetLogValue(point2.YValues[1]);
						double num19 = this.vAxis.GetLogValue(point2.YValues[2]);
						num17 = this.hAxis.GetLogValue(num17);
						if ((((num17 < this.hAxis.ViewMinimum) || (num17 > this.hAxis.ViewMaximum)) || ((num18 < this.vAxis.ViewMinimum) && (num19 < this.vAxis.ViewMinimum))) || ((num18 > this.vAxis.ViewMaximum) && (num19 > this.vAxis.ViewMaximum)))
						{
							pointIndex++;
							continue;
						}
						double y = this.vAxis.GetLogValue(point2.YValues[2]);
						double viewMaximum = this.vAxis.GetLogValue(point2.YValues[1]);
						if (point2.IsCustomPropertySet("ErrorBarStyle") || series.IsCustomPropertySet("ErrorBarStyle"))
						{
							string str6 = series["ErrorBarStyle"];
							if (point2.IsCustomPropertySet("ErrorBarStyle"))
							{
								str6 = point2["ErrorBarStyle"];
							}
							if (string.Compare(str6, "Both", StringComparison.OrdinalIgnoreCase) != 0)
							{
								if (string.Compare(str6, "UpperError", StringComparison.OrdinalIgnoreCase) != 0)
								{
									if (string.Compare(str6, "LowerError", StringComparison.OrdinalIgnoreCase) != 0)
									{
										throw new InvalidOperationException(SR.ExceptionCustomAttributeValueInvalid(point2["ErrorBarStyle"], "ErrorBarStyle"));
									}
									viewMaximum = this.vAxis.GetLogValue(point2.YValues[1]);
									y = this.vAxis.GetLogValue(point2.YValues[0]);
								}
								else
								{
									viewMaximum = this.vAxis.GetLogValue(point2.YValues[0]);
									y = this.vAxis.GetLogValue(point2.YValues[2]);
								}
							}
						}
						if (y > this.vAxis.ViewMaximum)
						{
							y = this.vAxis.ViewMaximum;
						}
						if (y < this.vAxis.ViewMinimum)
						{
							y = this.vAxis.ViewMinimum;
						}
						y = (float)this.vAxis.GetLinearPosition(y);
						if (viewMaximum > this.vAxis.ViewMaximum)
						{
							viewMaximum = this.vAxis.ViewMaximum;
						}
						if (viewMaximum < this.vAxis.ViewMinimum)
						{
							viewMaximum = this.vAxis.ViewMinimum;
						}
						viewMaximum = this.vAxis.GetLinearPosition(viewMaximum);
						Point3D[] pointdArray2 = new Point3D[] { new Point3D(position, (float)y, num8 + (num7 / 2f)), new Point3D(position, (float)viewMaximum, num8 + (num7 / 2f)) };
						area.matrix3D.TransformPoints(pointdArray2);
						position = pointdArray2[0].X;
						y = pointdArray2[0].Y;
						viewMaximum = pointdArray2[1].Y;
						this.DrawLabel(common, area, graph, series, point2, new PointF(position, (float)Math.Min(y, viewMaximum)), pointIndex);
						pointIndex++;
					}
				}
				if (!selection)
				{
					common.Chart.CallOnPostPaint(new ChartPaintEventArgs(series, graph, common, area.PlotAreaPosition));
				}
			}
		}

		public virtual bool ApplyPaletteColorsToPoints
		{
			get
			{
				return false;
			}
		}

		public bool CircularChartArea
		{
			get
			{
				return false;
			}
		}

		public virtual bool DataPointsInLegend
		{
			get
			{
				return false;
			}
		}

		public virtual bool ExtraYValuesConnectedToYAxis
		{
			get
			{
				return true;
			}
		}

		public virtual bool HundredPercent
		{
			get
			{
				return false;
			}
		}

		public virtual bool HundredPercentSupportNegative
		{
			get
			{
				return false;
			}
		}

		public virtual string Name
		{
			get
			{
				return "ErrorBar";
			}
		}

		public virtual bool RequireAxes
		{
			get
			{
				return true;
			}
		}

		public bool SecondYScale
		{
			get
			{
				return false;
			}
		}

		public bool SideBySideSeries
		{
			get
			{
				return false;
			}
		}

		public virtual bool Stacked
		{
			get
			{
				return false;
			}
		}

		public bool StackSign
		{
			get
			{
				return false;
			}
		}

		public virtual bool SupportLogarithmicAxes
		{
			get
			{
				return true;
			}
		}

		public virtual bool SupportStackedGroups
		{
			get
			{
				return false;
			}
		}

		public virtual bool SwitchValueAxes
		{
			get
			{
				return false;
			}
		}

		public virtual int YValuesPerPoint
		{
			get
			{
				return 3;
			}
		}

		public virtual bool ZeroCrossing
		{
			get
			{
				return false;
			}
		}
	}
}

